package mywebapps.beans;

import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import mywebapps.dao.ArtProductDao;
import mywebapps.model.ArtProduct;

@Named("imagesBean")
@ApplicationScoped
public class ImagesBean {
	public enum ImageType {PAINTING, SKETCH, PHOTOGRAPH};
	
	@Inject private ArtProductDao artProductDao;
	
	private String[] paintings;
	private String[] sketches;
	private String[] photographs;
	
    public String[] getPaintings() {
    	if(paintings == null) {
    		synchronized(this) {
    			if(paintings == null) {
    				List<ArtProduct> artProducts = artProductDao.getArtProducts("PAINTING");
    				paintings = new String[artProducts.size()];
    		    	for(int i = 0; i < artProducts.size(); i++) {
    		    		paintings[i] = artProducts.get(i).getFilename();
    		    	}
    			}
    		}
    	}
    	
    	return paintings;
    }
    
    public String[] getSketches() {
    	if(sketches == null) {
    		synchronized(this) {
    			if(sketches == null) {
    				List<ArtProduct> artProducts = artProductDao.getArtProducts("SKETCH");
    				sketches = new String[artProducts.size()];
    		    	for(int i = 0; i < artProducts.size(); i++) {
    		    		sketches[i] = artProducts.get(i).getFilename();
    		    	}
    			}
    		}
    	}
    	
    	return sketches;
    }
    
    public String[] getPhotographs() {
    	if(photographs == null) {
    		synchronized(this) {
    			if(photographs == null) {
    				List<ArtProduct> artProducts = artProductDao.getArtProducts("PHOTOGRAPH");
    				photographs = new String[artProducts.size()];
    		    	for(int i = 0; i < artProducts.size(); i++) {
    		    		photographs[i] = artProducts.get(i).getFilename();
    		    	}
    			}
    		}
    	}
    	
    	return photographs;
    }
}
